<?php if ($categories): ?>
<section rel="categories" class="categories box">
    <header>
        <div class="buttons buttons-small float-left">
            <?php echo anchor('admin/blog/categories/create/', lang('cat_create_title'), 'rel="categories" class="add ajax button"') ?>
        </div>
        <h3 class="spacer-bottom-half"><?php echo lang('cat_list_title'); ?></h3>
        <h3 class="form-title"></h3>
    </header>

    <?php if (!empty($categories)): ?>

    <div class="box-container collapsed">

        <div id="link-list">
            <ol class="sortable">
                <?php foreach ($categories as $category): ?>
									<li id="category_<?php echo $category['id']; ?>">
										<div>
                                            <a href="#" rel="categories"
                                               alt="<?php echo $category['id']; ?>"><?php echo $category['title']; ?></a>
                                        </div>
                <?php
                if (!empty($category['children'])): ?>
                    <ol>
                        <?php $controller->tree_builder($category); ?>
                    </ol>
									</li>
								<?php else: ?>
                    </li>
                    <?php endif; ?>

                <?php endforeach; ?>

            </ol>
        </div>

        <div id="link-details" class="categories">
            <p>
                <?php echo lang('cat_tree_explanation'); ?>
            </p>
        </div>
        <br class="clear-both"/>

    </div>

    <?php else: ?>
    <div class="box-container collapsed">

        <div id="link-list" class="empty">
            <ol class="sortable">

                <p><?php echo lang('cat_no_categories');?></p>

            </ol>
        </div>

        <div id="link-details" class="group-<?php echo $group->id; ?>">

            <p>
                <?php echo lang('cat_tree_explanation'); ?>
            </p>

        </div>

        <br class="clear-both"/>

    </div>
    <?php endif; ?>

</section>
<?php echo form_open('admin/blog/categories/delete'); ?>

<table border="0" class="table-list">
    <thead>
    <tr>
        <th width="20"><?php echo form_checkbox(array('name' => 'action_to_all', 'class' => 'check-all')); ?></th>
        <th></th>
        <th width="200" class="align-center"><span><?php echo lang('cat_actions_label'); ?></span></th>
    </tr>
    </thead>
    <tfoot>
    <tr>
        <td colspan="3">
            <div class="inner"><?php $this->load->view('admin/partials/pagination'); ?></div>
        </td>
    </tr>
    </tfoot>
    <tbody>
        <?php foreach ($categories as $category): ?>
    <tr>
        <td><?php echo form_checkbox('action_to[]', $category->id); ?></td>
        <td><?php echo $category->title; ?></td>
        <td class="align-center buttons buttons-small">
            <?php echo anchor('admin/blog/categories/edit/' . $category->id, lang('cat_edit_label'), 'class="button edit"'); ?>
            <?php echo anchor('admin/blog/categories/delete/' . $category->id, lang('cat_delete_label'), 'class="confirm button delete"');?>
        </td>
    </tr>
        <?php endforeach; ?>
    </tbody>
</table>

<div class="buttons align-right padding-top">
    <?php $this->load->view('admin/partials/buttons', array('buttons' => array('delete'))); ?>
</div>

<?php echo form_close(); ?>

<?php else: ?>
<div class="blank-slate">
    <h2><?php echo lang('cat_no_categories'); ?></h2>
</div>
<?php endif; ?>